
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>15.1 如何开始迁移项目 · 《CMake Cookbook》中文版</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="陈晓伟 chenxiaowei">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="15.2-chinese.html" />
    
    
    <link rel="prev" href="15.0-chinese.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../preface/preface-chinese.html">
            
                <a href="../preface/preface-chinese.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../chapter0/0.0-chinese.html">
            
                <a href="../chapter0/0.0-chinese.html">
            
                    
                    第0章 配置环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter0/0.1-chinese.html">
            
                <a href="../chapter0/0.1-chinese.html">
            
                    
                    0.1 获取代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../chapter0/0.2-chinese.html">
            
                <a href="../chapter0/0.2-chinese.html">
            
                    
                    0.2 Docker镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../chapter0/0.3-chinese.html">
            
                <a href="../chapter0/0.3-chinese.html">
            
                    
                    0.3 安装必要的软件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../chapter0/0.4-chinese.html">
            
                <a href="../chapter0/0.4-chinese.html">
            
                    
                    0.4 测试环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../chapter0/0.5-chinese.html">
            
                <a href="../chapter0/0.5-chinese.html">
            
                    
                    0.5 上报问题并提出改进建议
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../chapter1/1.0-chinese.html">
            
                <a href="../chapter1/1.0-chinese.html">
            
                    
                    第1章 从可执行文件到库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../chapter1/1.1-chinese.html">
            
                <a href="../chapter1/1.1-chinese.html">
            
                    
                    1.1 将单个源文件编译为可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../chapter1/1.2-chinese.html">
            
                <a href="../chapter1/1.2-chinese.html">
            
                    
                    1.2 切换生成器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../chapter1/1.3-chinese.html">
            
                <a href="../chapter1/1.3-chinese.html">
            
                    
                    1.3 构建和链接静态库和动态库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../chapter1/1.4-chinese.html">
            
                <a href="../chapter1/1.4-chinese.html">
            
                    
                    1.4 用条件句控制编译
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../chapter1/1.5-chinese.html">
            
                <a href="../chapter1/1.5-chinese.html">
            
                    
                    1.5 向用户显示选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../chapter1/1.6-chinese.html">
            
                <a href="../chapter1/1.6-chinese.html">
            
                    
                    1.6 指定编译器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../chapter1/1.7-chinese.html">
            
                <a href="../chapter1/1.7-chinese.html">
            
                    
                    1.7 切换构建类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../chapter1/1.8-chinese.html">
            
                <a href="../chapter1/1.8-chinese.html">
            
                    
                    1.8 设置编译器选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../chapter1/1.9-chinese.html">
            
                <a href="../chapter1/1.9-chinese.html">
            
                    
                    1.9 为语言设定标准
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../chapter1/1.10-chinese.html">
            
                <a href="../chapter1/1.10-chinese.html">
            
                    
                    1.10 使用控制流
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../chapter2/2.0-chinese.html">
            
                <a href="../chapter2/2.0-chinese.html">
            
                    
                    第2章 检测环境
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter2/2.1-chinese.html">
            
                <a href="../chapter2/2.1-chinese.html">
            
                    
                    2.1 检测操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter2/2.2-chinese.html">
            
                <a href="../chapter2/2.2-chinese.html">
            
                    
                    2.2 处理与平台相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../chapter2/2.3-chinese.html">
            
                <a href="../chapter2/2.3-chinese.html">
            
                    
                    2.3 处理与编译器相关的源代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../chapter2/2.4-chinese.html">
            
                <a href="../chapter2/2.4-chinese.html">
            
                    
                    2.4 检测处理器体系结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../chapter2/2.5-chinese.html">
            
                <a href="../chapter2/2.5-chinese.html">
            
                    
                    2.5 检测处理器指令集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../chapter2/2.6-chinese.html">
            
                <a href="../chapter2/2.6-chinese.html">
            
                    
                    2.6 为Eigen库使能向量化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../chapter3/3.0-chinese.html">
            
                <a href="../chapter3/3.0-chinese.html">
            
                    
                    第3章 检测外部库和程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../chapter3/3.1-chinese.html">
            
                <a href="../chapter3/3.1-chinese.html">
            
                    
                    3.1 检测Python解释器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../chapter3/3.2-chinese.html">
            
                <a href="../chapter3/3.2-chinese.html">
            
                    
                    3.2 检测Python库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../chapter3/3.3-chinese.html">
            
                <a href="../chapter3/3.3-chinese.html">
            
                    
                    3.3 检测Python模块和包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../chapter3/3.4-chinese.html">
            
                <a href="../chapter3/3.4-chinese.html">
            
                    
                    3.4 检测BLAS和LAPACK数学库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../chapter3/3.5-chinese.html">
            
                <a href="../chapter3/3.5-chinese.html">
            
                    
                    3.5 检测OpenMP的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../chapter3/3.6-chinese.html">
            
                <a href="../chapter3/3.6-chinese.html">
            
                    
                    3.6 检测MPI的并行环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../chapter3/3.7-chinese.html">
            
                <a href="../chapter3/3.7-chinese.html">
            
                    
                    3.7 检测Eigen库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../chapter3/3.8-chinese.html">
            
                <a href="../chapter3/3.8-chinese.html">
            
                    
                    3.8 检测Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../chapter3/3.9-chinese.html">
            
                <a href="../chapter3/3.9-chinese.html">
            
                    
                    3.9 检测外部库:Ⅰ. 使用pkg-config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../chapter3/3.10-chinese.html">
            
                <a href="../chapter3/3.10-chinese.html">
            
                    
                    3.10 检测外部库:Ⅱ. 自定义find模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../chapter4/4.0-chinese.html">
            
                <a href="../chapter4/4.0-chinese.html">
            
                    
                    第4章 创建和运行测试
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../chapter4/4.1-chinese.html">
            
                <a href="../chapter4/4.1-chinese.html">
            
                    
                    4.1 创建一个简单的单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../chapter4/4.2-chinese.html">
            
                <a href="../chapter4/4.2-chinese.html">
            
                    
                    4.2 使用Catch2库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../chapter4/4.3-chinese.html">
            
                <a href="../chapter4/4.3-chinese.html">
            
                    
                    4.3 使用Google Test库进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../chapter4/4.4-chinese.html">
            
                <a href="../chapter4/4.4-chinese.html">
            
                    
                    4.4 使用Boost Test进行单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../chapter4/4.5-chinese.html">
            
                <a href="../chapter4/4.5-chinese.html">
            
                    
                    4.5 使用动态分析来检测内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../chapter4/4.6-chinese.html">
            
                <a href="../chapter4/4.6-chinese.html">
            
                    
                    4.6 预期测试失败
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../chapter4/4.7-chinese.html">
            
                <a href="../chapter4/4.7-chinese.html">
            
                    
                    4.7 使用超时测试运行时间过长的测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../chapter4/4.8-chinese.html">
            
                <a href="../chapter4/4.8-chinese.html">
            
                    
                    4.8 并行测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../chapter4/4.9-chinese.html">
            
                <a href="../chapter4/4.9-chinese.html">
            
                    
                    4.9 运行测试子集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../chapter4/4.10-chinese.html">
            
                <a href="../chapter4/4.10-chinese.html">
            
                    
                    4.10 使用测试固件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../chapter5/5.0-chinese.html">
            
                <a href="../chapter5/5.0-chinese.html">
            
                    
                    第5章 配置时和构建时的操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../chapter5/5.1-chinese.html">
            
                <a href="../chapter5/5.1-chinese.html">
            
                    
                    5.1 使用平台无关的文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../chapter5/5.2-chinese.html">
            
                <a href="../chapter5/5.2-chinese.html">
            
                    
                    5.2 配置时运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../chapter5/5.3-chinese.html">
            
                <a href="../chapter5/5.3-chinese.html">
            
                    
                    5.3 构建时运行自定义命令:Ⅰ. 使用add_custom_command
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../chapter5/5.4-chinese.html">
            
                <a href="../chapter5/5.4-chinese.html">
            
                    
                    5.4 构建时运行自定义命令:Ⅱ. 使用add_custom_target
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../chapter5/5.5-chinese.html">
            
                <a href="../chapter5/5.5-chinese.html">
            
                    
                    5.5 构建时为特定目标运行自定义命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../chapter5/5.6-chinese.html">
            
                <a href="../chapter5/5.6-chinese.html">
            
                    
                    5.6 探究编译和链接命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../chapter5/5.7-chinese.html">
            
                <a href="../chapter5/5.7-chinese.html">
            
                    
                    5.7 探究编译器标志命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../chapter5/5.8-chinese.html">
            
                <a href="../chapter5/5.8-chinese.html">
            
                    
                    5.8 探究可执行命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../chapter5/5.9-chinese.html">
            
                <a href="../chapter5/5.9-chinese.html">
            
                    
                    5.9 使用生成器表达式微调配置和编译
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../chapter6/6.0-chinese.html">
            
                <a href="../chapter6/6.0-chinese.html">
            
                    
                    第6章 生成源码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../chapter6/6.1-chinese.html">
            
                <a href="../chapter6/6.1-chinese.html">
            
                    
                    6.1 配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../chapter6/6.2-chinese.html">
            
                <a href="../chapter6/6.2-chinese.html">
            
                    
                    6.2 使用Python在配置时生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.3" data-path="../chapter6/6.3-chinese.html">
            
                <a href="../chapter6/6.3-chinese.html">
            
                    
                    6.3 构建时使用Python生成源码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.4" data-path="../chapter6/6.4-chinese.html">
            
                <a href="../chapter6/6.4-chinese.html">
            
                    
                    6.4 记录项目版本信息以便报告
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.5" data-path="../chapter6/6.5-chinese.html">
            
                <a href="../chapter6/6.5-chinese.html">
            
                    
                    6.5 从文件中记录项目版本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.6" data-path="../chapter6/6.6-chinese.html">
            
                <a href="../chapter6/6.6-chinese.html">
            
                    
                    6.6 配置时记录Git Hash值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.7" data-path="../chapter6/6.7-chinese.html">
            
                <a href="../chapter6/6.7-chinese.html">
            
                    
                    6.7 构建时记录Git Hash值
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../chapter7/7.0-chinese.html">
            
                <a href="../chapter7/7.0-chinese.html">
            
                    
                    第7章 构建项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../chapter7/7.1-chinese.html">
            
                <a href="../chapter7/7.1-chinese.html">
            
                    
                    7.1 使用函数和宏重用代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../chapter7/7.2-chinese.html">
            
                <a href="../chapter7/7.2-chinese.html">
            
                    
                    7.2 将CMake源代码分成模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../chapter7/7.3-chinese.html">
            
                <a href="../chapter7/7.3-chinese.html">
            
                    
                    7.3 编写函数来测试和设置编译器标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../chapter7/7.4-chinese.html">
            
                <a href="../chapter7/7.4-chinese.html">
            
                    
                    7.4 用指定参数定义函数或宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../chapter7/7.5-chinese.html">
            
                <a href="../chapter7/7.5-chinese.html">
            
                    
                    7.5 重新定义函数和宏
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../chapter7/7.6-chinese.html">
            
                <a href="../chapter7/7.6-chinese.html">
            
                    
                    7.6 使用废弃函数、宏和变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../chapter7/7.7-chinese.html">
            
                <a href="../chapter7/7.7-chinese.html">
            
                    
                    7.7 add_subdirectory的限定范围
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../chapter7/7.8-chinese.html">
            
                <a href="../chapter7/7.8-chinese.html">
            
                    
                    7.8 使用target_sources避免全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../chapter7/7.9-chinese.html">
            
                <a href="../chapter7/7.9-chinese.html">
            
                    
                    7.9 组织Fortran项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../chapter8/8.0-chinese.html">
            
                <a href="../chapter8/8.0-chinese.html">
            
                    
                    第8章 超级构建模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../chapter8/8.1-chinese.html">
            
                <a href="../chapter8/8.1-chinese.html">
            
                    
                    8.1 使用超级构建模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../chapter8/8.2-chinese.html">
            
                <a href="../chapter8/8.2-chinese.html">
            
                    
                    8.2 使用超级构建管理依赖项:Ⅰ.Boost库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../chapter8/8.3-chinese.html">
            
                <a href="../chapter8/8.3-chinese.html">
            
                    
                    8.3 使用超级构建管理依赖项:Ⅱ.FFTW库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../chapter8/8.4-chinese.html">
            
                <a href="../chapter8/8.4-chinese.html">
            
                    
                    8.4 使用超级构建管理依赖项:Ⅲ.Google Test框架
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../chapter8/8.5-chinese.html">
            
                <a href="../chapter8/8.5-chinese.html">
            
                    
                    8.5 使用超级构建支持项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../chapter9/9.0-chinese.html">
            
                <a href="../chapter9/9.0-chinese.html">
            
                    
                    第9章 语言混合项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../chapter9/9.1-chinese.html">
            
                <a href="../chapter9/9.1-chinese.html">
            
                    
                    9.1 使用C/C++库构建Fortran项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../chapter9/9.2-chinese.html">
            
                <a href="../chapter9/9.2-chinese.html">
            
                    
                    9.2 使用Fortran库构建C/C++项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../chapter9/9.3-chinese.html">
            
                <a href="../chapter9/9.3-chinese.html">
            
                    
                    9.3 使用Cython构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../chapter9/9.4-chinese.html">
            
                <a href="../chapter9/9.4-chinese.html">
            
                    
                    9.4 使用Boost.Python构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.5" data-path="../chapter9/9.5-chinese.html">
            
                <a href="../chapter9/9.5-chinese.html">
            
                    
                    9.5 使用pybind11构建C++和Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.6" data-path="../chapter9/9.6-chinese.html">
            
                <a href="../chapter9/9.6-chinese.html">
            
                    
                    9.6 使用Python CFFI混合C，C++，Fortran和Python
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../chapter10/10.0-chinese.html">
            
                <a href="../chapter10/10.0-chinese.html">
            
                    
                    第10章 编写安装程序
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../chapter10/10.1-chinese.html">
            
                <a href="../chapter10/10.1-chinese.html">
            
                    
                    10.1 安装项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../chapter10/10.2-chinese.html">
            
                <a href="../chapter10/10.2-chinese.html">
            
                    
                    10.2 生成输出头文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../chapter10/10.3-chinese.html">
            
                <a href="../chapter10/10.3-chinese.html">
            
                    
                    10.3 输出目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../chapter10/10.4-chinese.html">
            
                <a href="../chapter10/10.4-chinese.html">
            
                    
                    10.4 安装超级构建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../chapter11/11.0-chinese.html">
            
                <a href="../chapter11/11.0-chinese.html">
            
                    
                    第11章 打包项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../chapter11/11.1-chinese.html">
            
                <a href="../chapter11/11.1-chinese.html">
            
                    
                    11.1 生成源代码和二进制包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../chapter11/11.2-chinese.html">
            
                <a href="../chapter11/11.2-chinese.html">
            
                    
                    11.2 通过PyPI发布使用CMake/pybind11构建的C++/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../chapter11/11.3-chinese.html">
            
                <a href="../chapter11/11.3-chinese.html">
            
                    
                    11.3 通过PyPI发布使用CMake/CFFI构建C/Fortran/Python项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.4" data-path="../chapter11/11.4-chinese.html">
            
                <a href="../chapter11/11.4-chinese.html">
            
                    
                    11.4 以Conda包的形式发布一个简单的项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.5" data-path="../chapter11/11.5-chinese.html">
            
                <a href="../chapter11/11.5-chinese.html">
            
                    
                    11.5 将Conda包作为依赖项发布给项目
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../chapter12/12.0-chinese.html">
            
                <a href="../chapter12/12.0-chinese.html">
            
                    
                    第12章 构建文档
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../chapter12/12.1-chinese.html">
            
                <a href="../chapter12/12.1-chinese.html">
            
                    
                    12.1 使用Doxygen构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../chapter12/12.2-chinese.html">
            
                <a href="../chapter12/12.2-chinese.html">
            
                    
                    12.2 使用Sphinx构建文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../chapter12/12.3-chinese.html">
            
                <a href="../chapter12/12.3-chinese.html">
            
                    
                    12.3 结合Doxygen和Sphinx
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../chapter13/13.0-chinese.html">
            
                <a href="../chapter13/13.0-chinese.html">
            
                    
                    第13章 选择生成器和交叉编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.16.1" data-path="../chapter13/13.1-chinese.html">
            
                <a href="../chapter13/13.1-chinese.html">
            
                    
                    13.1 使用CMake构建Visual Studio 2017项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.2" data-path="../chapter13/13.2-chinese.html">
            
                <a href="../chapter13/13.2-chinese.html">
            
                    
                    13.2 交叉编译hello world示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16.3" data-path="../chapter13/13.3-chinese.html">
            
                <a href="../chapter13/13.3-chinese.html">
            
                    
                    13.3 使用OpenMP并行化交叉编译Windows二进制文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../chapter14/14.0-chinese.html">
            
                <a href="../chapter14/14.0-chinese.html">
            
                    
                    第14章 测试面板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../chapter14/14.1-chinese.html">
            
                <a href="../chapter14/14.1-chinese.html">
            
                    
                    14.1 将测试部署到CDash
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../chapter14/14.2-chinese.html">
            
                <a href="../chapter14/14.2-chinese.html">
            
                    
                    14.2 CDash显示测试覆盖率
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../chapter14/14.3-chinese.html">
            
                <a href="../chapter14/14.3-chinese.html">
            
                    
                    14.3 使用AddressSanifier向CDash报告内存缺陷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../chapter14/14.4-chinese.html">
            
                <a href="../chapter14/14.4-chinese.html">
            
                    
                    14.4 使用ThreadSaniiser向CDash报告数据争用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="15.0-chinese.html">
            
                <a href="15.0-chinese.html">
            
                    
                    第15章 使用CMake构建已有项目
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.18.1" data-path="15.1-chinese.html">
            
                <a href="15.1-chinese.html">
            
                    
                    15.1 如何开始迁移项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.2" data-path="15.2-chinese.html">
            
                <a href="15.2-chinese.html">
            
                    
                    15.2 生成文件并编写平台检查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.3" data-path="15.3-chinese.html">
            
                <a href="15.3-chinese.html">
            
                    
                    15.3 检测所需的链接和依赖关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.4" data-path="15.4-chinese.html">
            
                <a href="15.4-chinese.html">
            
                    
                    15.4 复制编译标志
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.5" data-path="15.5-chinese.html">
            
                <a href="15.5-chinese.html">
            
                    
                    15.5 移植测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.6" data-path="15.6-chinese.html">
            
                <a href="15.6-chinese.html">
            
                    
                    15.6 移植安装目标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.7" data-path="15.7-chinese.html">
            
                <a href="15.7-chinese.html">
            
                    
                    15.7 进一步迁移的措施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18.8" data-path="15.8-chinese.html">
            
                <a href="15.8-chinese.html">
            
                    
                    15.8 项目转换为CMake的常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../chapter16/16.0-chinese.html">
            
                <a href="../chapter16/16.0-chinese.html">
            
                    
                    第16章 可能感兴趣的书
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.19.1" data-path="../chapter16/16.1-chinese.html">
            
                <a href="../chapter16/16.1-chinese.html">
            
                    
                    16.1 留下评论——让其他读者知道你的想法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="http://www.bczl.xyz/" target="blank" class="gitbook-link">
            编程之路
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >15.1 如何开始迁移项目</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="151-&#x5982;&#x4F55;&#x5F00;&#x59CB;&#x8FC1;&#x79FB;&#x9879;&#x76EE;">15.1 &#x5982;&#x4F55;&#x5F00;&#x59CB;&#x8FC1;&#x79FB;&#x9879;&#x76EE;</h1>
<p>&#x6211;&#x4EEC;&#x5C06;&#x9996;&#x5148;&#x8BF4;&#x660E;&#xFF0C;&#x5728;&#x54EA;&#x91CC;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#xFF0C;&#x7136;&#x540E;&#x5BF9;&#x79FB;&#x690D;&#xFF0C;&#x8FDB;&#x884C;&#x9010;&#x6B65;&#x7684;&#x8BA8;&#x8BBA;&#x3002;</p>
<h2 id="&#x590D;&#x5236;&#x8981;&#x79FB;&#x690D;&#x7684;&#x793A;&#x4F8B;">&#x590D;&#x5236;&#x8981;&#x79FB;&#x690D;&#x7684;&#x793A;&#x4F8B;</h2>
<p>&#x6211;&#x4EEC;&#x5C06;&#x4ECE;Vim&#x6E90;&#x4EE3;&#x7801;&#x5E93;&#x7684;v8.1.0290&#x53D1;&#x884C;&#x6807;&#x8BB0;&#x5F00;&#x59CB;(<a href="https://github.com/vim/vim" target="_blank">https://github.com/vim/vim</a>) &#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x5DE5;&#x4F5C;&#x57FA;&#x4E8E;Git&#x63D0;&#x4EA4;&#x54C8;&#x5E0C;&#x503C;b476cb7&#x8FDB;&#x884C;&#x3002;
&#x901A;&#x8FC7;&#x514B;&#x9686;Vim&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x5E93;&#x5E76;&#x68C0;&#x51FA;&#x7279;&#x5B9A;&#x7248;&#x672C;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x590D;&#x5236;&#x4EE5;&#x4E0B;&#x6B65;&#x9AA4;:</p>
<pre><code class="lang-shell">$ git clone --single-branch -b v8.1.0290 https://github.com/vim/vim.git
</code></pre>
<p>&#x6216;&#x8005;&#xFF0C;&#x6211;&#x4EEC;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x53EF;&#x4EE5;&#x5728;<code>cmake-support</code>&#x5206;&#x652F;&#x4E0A;&#x627E;&#x5230;&#xFF0C;&#x7F51;&#x5740;&#x662F; <a href="https://github.com/dev-cafe/vim" target="_blank">https://github.com/dev-cafe/vim</a> &#xFF0C;&#x5E76;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#x514B;&#x9686;&#x4E0B;&#x6765;:</p>
<pre><code class="lang-shell">$ git clone --single-branch -b cmake-support https://github.com/dev-cafe/vim
</code></pre>
<p>&#x5728;&#x672C;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;CMake&#x6A21;&#x62DF;<code>./configure --enable-gui=no</code>&#x7684;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x4E0E;&#x540E;&#x9762;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x8FDB;&#x884C;&#x6BD4;&#x8F83;&#xFF0C;&#x5EFA;&#x8BAE;&#x8BFB;&#x8005;&#x4E5F;&#x53EF;&#x4EE5;&#x7814;&#x7A76;&#x4EE5;&#x4E0B;Neovim&#x9879;&#x76EE;(<a href="https://github.com/neovim/neovim" target="_blank">https://github.com/neovim/neovim</a> )&#xFF0C;&#x8FD9;&#x662F;&#x4F20;&#x7EDF;Vi&#x7F16;&#x8F91;&#x5668;&#x7684;&#x4E00;&#x4E2A;&#x5206;&#x652F;&#xFF0C;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;CMake&#x6784;&#x5EFA;&#x7CFB;&#x7EDF;&#x3002;</p>
<h2 id="&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4E3B;cmakeliststxt">&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4E3B;CMakeLists.txt</h2>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x5728;&#x6E90;&#x4EE3;&#x7801;&#x5B58;&#x50A8;&#x5E93;&#x7684;&#x6839;&#x76EE;&#x5F55;&#x4E2D;&#x521B;&#x5EFA;&#x4E3B;<code>CMakeLists.txt</code>&#xFF0C;&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x8BBE;&#x7F6E;&#x4E86;&#x6700;&#x4F4E;CMake&#x7248;&#x672C;&#x3001;&#x9879;&#x76EE;&#x540D;&#x79F0;&#x548C;&#x652F;&#x6301;&#x7684;&#x8BED;&#x8A00;&#xFF0C;&#x5728;&#x672C;&#x4F8B;&#x4E2D;&#x662F;C&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">cmake_minimum_required</span>(VERSION
<span class="hljs-number">3.5</span> FATAL_ERROR)
<span class="hljs-keyword">project</span>(vim LANGUAGES C)
</code></pre>
<p>&#x6DFB;&#x52A0;&#x4EFB;&#x4F55;&#x76EE;&#x6807;&#x6216;&#x6E90;&#x4E4B;&#x524D;&#xFF0C;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x7684;&#x6784;&#x5EFA;&#x7C7B;&#x578B;&#x3002;&#x672C;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x9ED8;&#x8BA4;&#x4E3A;Release&#x914D;&#x7F6E;&#xFF0C;&#x8FD9;&#x5C06;&#x6253;&#x5F00;&#x67D0;&#x4E9B;&#x7F16;&#x8BD1;&#x5668;&#x4F18;&#x5316;&#x9009;&#x9879;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(NOT CMAKE_BUILD_TYPE)
    <span class="hljs-keyword">set</span>(CMAKE_BUILD_TYPE Release CACHE <span class="hljs-keyword">STRING</span> <span class="hljs-string">&quot;Build type&quot;</span> FORCE)
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E5F;&#x4F7F;&#x7528;&#x53EF;&#x79FB;&#x690D;&#x7684;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x53D8;&#x91CF;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">include</span>(GNUInstallDirs)
<span class="hljs-keyword">set</span>(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
    <span class="hljs-variable">${CMAKE_BINARY_DIR}</span>/<span class="hljs-variable">${CMAKE_INSTALL_LIBDIR}</span>)
<span class="hljs-keyword">set</span>(CMAKE_LIBRARY_OUTPUT_DIRECTORY
    <span class="hljs-variable">${CMAKE_BINARY_DIR}</span>/<span class="hljs-variable">${CMAKE_INSTALL_LIBDIR}</span>)
<span class="hljs-keyword">set</span>(CMAKE_RUNTIME_OUTPUT_DIRECTORY
    <span class="hljs-variable">${CMAKE_BINARY_DIR}</span>/<span class="hljs-variable">${CMAKE_INSTALL_BINDIR}</span>)
</code></pre>
<p>&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x6027;&#x68C0;&#x67E5;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C1D;&#x8BD5;&#x914D;&#x7F6E;&#x548C;&#x6784;&#x5EFA;&#x9879;&#x76EE;&#xFF0C;&#x4F46;&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#x8FD8;&#x6CA1;&#x6709;&#x76EE;&#x6807;&#xFF0C;&#x6240;&#x4EE5;&#x6784;&#x5EFA;&#x6B65;&#x9AA4;&#x7684;&#x8F93;&#x51FA;&#x662F;&#x7A7A;&#x7684;:</p>
<pre><code class="lang-shell">$ mkdir -p build
$ cd build
$ cmake ..
$ cmake --build .
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E00;&#x4F1A;&#x513F;&#x5C31;&#x8981;&#x5F00;&#x59CB;&#x6DFB;&#x52A0;&#x76EE;&#x6807;&#x4E86;&#x3002;</p>
<h2 id="&#x5982;&#x4F55;&#x8BA9;&#x5E38;&#x89C4;&#x548C;cmake&#x914D;&#x7F6E;&#x5171;&#x5B58;">&#x5982;&#x4F55;&#x8BA9;&#x5E38;&#x89C4;&#x548C;CMake&#x914D;&#x7F6E;&#x5171;&#x5B58;</h2>
<p>CMake&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x6027;&#x662F;&#x5728;&#x6E90;&#x4EE3;&#x7801;&#x4E4B;&#x5916;&#x6784;&#x5EFA;&#xFF0C;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x4F55;&#x76EE;&#x5F55;&#xFF0C;&#x800C;&#x4E0D;&#x5FC5;&#x662F;&#x9879;&#x76EE;&#x76EE;&#x5F55;&#x7684;&#x5B50;&#x76EE;&#x5F55;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#x79FB;&#x690D;&#x5230;CMake&#xFF0C;&#x800C;&#x4E0D;&#x5F71;&#x54CD;&#x4EE5;&#x524D;/&#x73B0;&#x5728;&#x7684;&#x914D;&#x7F6E;&#x548C;&#x6784;&#x5EFA;&#x673A;&#x5236;&#x3002;&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x91CD;&#x8981;&#x9879;&#x76EE;&#x7684;&#x8FC1;&#x79FB;&#xFF0C;CMake&#x6587;&#x4EF6;&#x53EF;&#x4EE5;&#x4E0E;&#x5176;&#x4ED6;&#x6784;&#x5EFA;&#x6846;&#x67B6;&#x5171;&#x5B58;&#xFF0C;&#x4ECE;&#x800C;&#x5141;&#x8BB8;&#x4E00;&#x4E2A;&#x6E10;&#x8FDB;&#x7684;&#x8FC1;&#x79FB;&#xFF0C;&#x5305;&#x62EC;&#x9009;&#x9879;&#x3001;&#x7279;&#x6027;&#x548C;&#x53EF;&#x79FB;&#x690D;&#x6027;&#xFF0C;&#x5E76;&#x5141;&#x8BB8;&#x5F00;&#x53D1;&#x793E;&#x533A;&#x4EBA;&#x5458;&#x9002;&#x5E94;&#x65B0;&#x7684;&#x6846;&#x67B6;&#x3002;&#x4E3A;&#x4E86;&#x5141;&#x8BB8;&#x4F20;&#x7EDF;&#x914D;&#x7F6E;&#x548C;CMake&#x914D;&#x7F6E;&#x5171;&#x5B58;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#xFF0C;&#x4E00;&#x4E2A;&#x5178;&#x578B;&#x7684;&#x7B56;&#x7565;&#x662F;&#x6536;&#x96C6;<code>CMakeLists.txt</code>&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6240;&#x6709;CMake&#x4EE3;&#x7801;&#xFF0C;&#x4EE5;&#x53CA;CMake&#x5B50;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6240;&#x6709;&#x8F85;&#x52A9;CMake&#x6E90;&#x6587;&#x4EF6;&#x7684;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x4F1A;&#x5F15;&#x5165;CMake&#x5B50;&#x76EE;&#x5F55;&#xFF0C;&#x800C;&#x662F;&#x4FDD;&#x6301;&#x8F85;&#x52A9;&#x6587;&#x4EF6;&#x8981;&#x6C42;&#x4ED6;&#x4EEC;&#x63A5;&#x8FD1;&#x76EE;&#x6807;&#x548C;&#x6765;&#x6E90;&#xFF0C;&#x4F46;&#x4F1A;&#x987E;&#x53CA;&#x4F7F;&#x7528;&#x7684;&#x4F20;&#x7EDF;Autotools&#x6784;&#x5EFA;&#x4FEE;&#x6539;&#x7684;&#x6240;&#x6709;&#x6587;&#x4EF6;&#xFF0C;&#x4F46;&#x6709;&#x4E00;&#x4E2A;&#x4F8B;&#x5916;&#xFF1A;&#x6211;&#x4EEC;&#x5C06;&#x4E00;&#x4E9B;&#x4FEE;&#x6539;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x6587;&#x4EF6;&#x6784;&#x5EFA;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5728;&#x6E90;&#x4EE3;&#x7801;&#x6811;&#x4E2D;&#x3002;</p>
<pre><code class="lang-shell">$ ./configure --enable-gui=no

... lot of output ...

$ make &gt; build.log
</code></pre>
<p>&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4E2D;(&#x8FD9;&#x91CC;&#x6CA1;&#x6709;&#x663E;&#x793A;build.log&#x7684;&#x5185;&#x5BB9;)&#xFF0C;&#x6211;&#x4EEC;&#x80FD;&#x591F;&#x9A8C;&#x8BC1;&#x7F16;&#x8BD1;&#x4E86;&#x54EA;&#x4E9B;&#x6E90;&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x4F7F;&#x7528;&#x4E86;&#x54EA;&#x4E9B;&#x7F16;&#x8BD1;&#x6807;&#x5FD7;(<code>-I. -Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1</code>)&#x3002;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x505A;&#x5982;&#x4E0B;&#x63A8;&#x65AD;:</p>
<ul>
<li>&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x6587;&#x4EF6;&#x90FD;&#x94FE;&#x63A5;&#x5230;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#x4E2D;</li>
<li>&#x4E0D;&#x751F;&#x6210;&#x5E93;</li>
<li>&#x53EF;&#x6267;&#x884C;&#x76EE;&#x6807;&#x4E0E;&#x4E0B;&#x5217;&#x5E93;&#x8FDB;&#x884C;&#x8FDE;&#x63A5;:<code>-lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lelf -lnsl -lacl -lattr -lgpm -ldl</code></li>
</ul>
<p>&#x901A;&#x8FC7;&#x5728;&#x4F7F;&#x7528;<code>message</code>&#x5BF9;&#x5DE5;&#x7A0B;&#x8FDB;&#x884C;&#x8C03;&#x8BD5;&#x65F6;&#xFF0C;&#x9009;&#x62E9;&#x6DFB;&#x52A0;&#x9009;&#x9879;&#x3001;&#x76EE;&#x6807;&#x3001;&#x6E90;&#x548C;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x9010;&#x6B65;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x53EF;&#x5DE5;&#x4F5C;&#x7684;&#x6784;&#x5EFA;&#x3002;</p>
<h2 id="&#x83B7;&#x53D6;&#x4F20;&#x7EDF;&#x6784;&#x5EFA;&#x7684;&#x8BB0;&#x5F55;">&#x83B7;&#x53D6;&#x4F20;&#x7EDF;&#x6784;&#x5EFA;&#x7684;&#x8BB0;&#x5F55;</h2>
<p>&#x5411;&#x914D;&#x7F6E;&#x6DFB;&#x52A0;&#x4EFB;&#x4F55;&#x76EE;&#x6807;&#x4E4B;&#x524D;&#xFF0C;&#x901A;&#x5E38;&#x6709;&#x5FC5;&#x8981;&#x770B;&#x770B;&#x4F20;&#x7EDF;&#x6784;&#x5EFA;&#x7684;&#x884C;&#x4E3A;&#xFF0C;&#x5E76;&#x5C06;&#x914D;&#x7F6E;&#x548C;&#x6784;&#x5EFA;&#x6B65;&#x9AA4;&#x7684;&#x8F93;&#x51FA;&#x4FDD;&#x5B58;&#x5230;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x4E2D;&#x3002;&#x5BF9;&#x4E8E;&#x6211;&#x4EEC;&#x7684;Vim&#x793A;&#x4F8B;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;:</p>
<pre><code class="lang-shell">$ ./configure --enable-gui=no

... lot of output ...

$ make &gt; build.log
</code></pre>
<p>&#x793A;&#x4F8B;&#x4E2D;(&#x8FD9;&#x91CC;&#x6CA1;&#x6709;&#x663E;&#x793A;build.log&#x7684;&#x5B8C;&#x6574;&#x5185;&#x5BB9;)&#xFF0C;&#x6211;&#x4EEC;&#x80FD;&#x591F;&#x9A8C;&#x8BC1;&#x7F16;&#x8BD1;&#x4E86;&#x54EA;&#x4E9B;&#x6E90;&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x4F7F;&#x7528;&#x4E86;&#x54EA;&#x4E9B;&#x7F16;&#x8BD1;&#x6807;&#x5FD7;(<code>-I.-Iproto -DHAVE_CONFIG_H -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1</code>)&#x3002;&#x4ECE;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x63A8;&#x65AD;&#x5982;&#x4E0B;:</p>
<ul>
<li>&#x6240;&#x6709;&#x5BF9;&#x8C61;&#x6587;&#x4EF6;&#x90FD;&#x94FE;&#x63A5;&#x5230;&#x4E00;&#x4E2A;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#x4E2D;</li>
<li>&#x6CA1;&#x6709;&#x751F;&#x6210;&#x5E93;</li>
<li>&#x53EF;&#x6267;&#x884C;&#x76EE;&#x6807;&#x94FE;&#x63A5;&#x5230;&#x4EE5;&#x4E0B;&#x5E93;:<code>-lSM -lXpm -lXt -lX11 -lXdmcp -lSM -lSM - linfo -lelf -lnsl -lacl -lattr -lgpm -ldl</code></li>
</ul>
<h2 id="&#x8C03;&#x8BD5;&#x8FC1;&#x79FB;&#x9879;&#x76EE;">&#x8C03;&#x8BD5;&#x8FC1;&#x79FB;&#x9879;&#x76EE;</h2>
<p>&#x5F53;&#x76EE;&#x6807;&#x548C;&#x547D;&#x4EE4;&#x9010;&#x6E10;&#x79FB;&#x52A8;&#x5230;CMake&#x7AEF;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;<code>message</code>&#x547D;&#x4EE4;&#x6253;&#x5370;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x5C31;&#x975E;&#x5E38;&#x6709;&#x7528;&#x4E86;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">message</span>(STATUS <span class="hljs-string">&quot;for debugging printing the value of ${some_variable}&quot;</span>)
</code></pre>
<p>&#x5728;&#x4F7F;&#x7528;&#x6D88;&#x606F;&#x8FDB;&#x884C;&#x8C03;&#x8BD5;&#x65F6;&#xFF0C;&#x6DFB;&#x52A0;&#x9009;&#x9879;&#x3001;&#x76EE;&#x6807;&#x3001;&#x6E90;&#x548C;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x9010;&#x6B65;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x53EF;&#x5DE5;&#x4F5C;&#x7684;&#x6784;&#x5EFA;&#x3002;</p>
<h2 id="&#x5B9E;&#x73B0;&#x9009;&#x9879;">&#x5B9E;&#x73B0;&#x9009;&#x9879;</h2>
<p>&#x627E;&#x51FA;&#x4F20;&#x7EDF;&#x914D;&#x7F6E;&#x4E3A;&#x7528;&#x6237;&#x63D0;&#x4F9B;&#x7684;&#x9009;&#x9879;(&#x4F8B;&#x5982;&#xFF0C;&#x901A;&#x8FC7;<code>./configure --help</code>)&#x3002;Vim&#x9879;&#x76EE;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x975E;&#x5E38;&#x957F;&#x7684;&#x9009;&#x9879;&#x548C;&#x6807;&#x5FD7;&#x5217;&#x8868;&#xFF0C;&#x4E3A;&#x4E86;&#x4F7F;&#x672C;&#x7AE0;&#x7684;&#x8BA8;&#x8BBA;&#x4FDD;&#x6301;&#x7B80;&#x5355;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x5728;CMake&#x7AEF;&#x5B9E;&#x73B0;&#x56DB;&#x4E2A;&#x9009;&#x9879;:</p>
<pre><code class="lang-shell">--disable-netbeans Disable NetBeans integration support.
--disable-channel Disable process communication support.
--enable-terminal Enable terminal emulation support.
--with-features=TYPE tiny, small, normal, big or huge (default: huge)
</code></pre>
<p>&#x6211;&#x4EEC;&#x8FD8;&#x5C06;&#x5FFD;&#x7565;&#x4EFB;&#x4F55;GUI&#x652F;&#x6301;&#x548C;&#x6A21;&#x62DF;<code>--enable-gui=no</code>&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5C06;&#x4F7F;&#x793A;&#x4F8B;&#x590D;&#x6742;&#x5316;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x5C06;&#x5728;CMakeLists.txt&#x4E2D;&#x6DFB;&#x52A0;&#x4EE5;&#x4E0B;&#x9009;&#x9879;(&#x6709;&#x9ED8;&#x8BA4;&#x503C;)&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">option</span>(ENABLE_NETBEANS <span class="hljs-string">&quot;Enable netbeans&quot;</span> <span class="hljs-keyword">ON</span>)
<span class="hljs-keyword">option</span>(ENABLE_CHANNEL <span class="hljs-string">&quot;Enable channel&quot;</span> <span class="hljs-keyword">ON</span>)
<span class="hljs-keyword">option</span>(ENABLE_TERMINAL <span class="hljs-string">&quot;Enable terminal&quot;</span> <span class="hljs-keyword">ON</span>)
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;<code>cmake -D FEATURES=value</code>&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;<code>FEATURES</code>&#x6765;&#x6A21;&#x62DF;<code>--with-features</code>&#x6807;&#x5FD7;&#x3002;&#x5982;&#x679C;&#x4E0D;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#xFF0C;&#x5B83;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;&quot;huge&quot;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(NOT FEATURES)
    <span class="hljs-keyword">set</span>(FEATURES <span class="hljs-string">&quot;huge&quot;</span> CACHE <span class="hljs-keyword">STRING</span>
<span class="hljs-string">&quot;FEATURES chosen by the user at CMake configure time&quot;</span>)
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E3A;&#x4F7F;&#x7528;&#x8005;&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x503C;<code>FEATURES</code>:</p>
<pre><code class="lang-cmake">list(APPEND _available_features <span class="hljs-string">&quot;tiny&quot;</span> <span class="hljs-string">&quot;small&quot;</span> <span class="hljs-string">&quot;normal&quot;</span> <span class="hljs-string">&quot;big&quot;</span> <span class="hljs-string">&quot;huge&quot;</span>)
<span class="hljs-keyword">if</span>(NOT FEATURES IN_LIST _available_features)
    <span class="hljs-keyword">message</span>(FATAL_ERROR <span class="hljs-string">&quot;Unknown features: \&quot;${FEATURES}\&quot;. Allowed values are: ${_available_features}.&quot;</span>)
<span class="hljs-keyword">endif</span>()
<span class="hljs-keyword">set_property</span>(CACHE FEATURES PROPERTY STRINGS <span class="hljs-variable">${_available_features}</span>)
</code></pre>
<p>&#x6700;&#x540E;&#x4E00;&#x884C;<code>set_property(CACHE FEATURES PROPERTY STRINGS ${_available_features})</code>&#xFF0C;&#x5F53;&#x4F7F;&#x7528;<code>cmake-gui</code>&#x914D;&#x7F6E;&#x9879;&#x76EE;&#xFF0C;&#x5219;&#x6709;&#x6709;&#x4E0D;&#x9519;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x7528;&#x6237;&#x53EF;&#x6839;&#x636E;&#x9009;&#x62E9;&#x5B57;&#x6BB5;&#x6E05;&#x5355;&#xFF0C;&#x9009;&#x62E9;&#x5DF2;&#x7ECF;&#x5B9A;&#x4E49;&#x4E86;&#x7684;<code>FEATURES</code>(&#x53C2;&#x89C1;<a href="https://blog.kitware.com/constraining-values-with-comboboxes-in-cmake-cmake-gui/" target="_blank">https://blog.kitware.com/constraining-values-with-comboboxes-in-cmake-cmake-gui/</a> )&#x3002;</p>
<p>&#x9009;&#x9879;&#x53EF;&#x4EE5;&#x653E;&#x5728;&#x4E3B;<code>CMakeLists.txt</code>&#x4E2D;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x67E5;&#x8BE2;<code>ENABLE_NETBEANS</code>&#x3001;<code>ENABLE_CHANNEL</code>&#x3001;<code>ENABLE_TERMINAL</code>&#x548C;<code>FEATURES</code>&#x7684;&#x5B9A;&#x4E49;&#x9644;&#x8FD1;&#x3002;&#x524D;&#x4E00;&#x79CD;&#x7B56;&#x7565;&#x7684;&#x4F18;&#x70B9;&#x662F;&#xFF0C;&#x9009;&#x9879;&#x5217;&#x5728;&#x4E00;&#x4E2A;&#x5730;&#x65B9;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x904D;&#x5386;<code>CMakeLists.txt</code>&#x6587;&#x4EF6;&#x6765;&#x67E5;&#x627E;&#x9009;&#x9879;&#x7684;&#x5B9A;&#x4E49;&#x3002;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x8FD8;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x4EFB;&#x4F55;&#x76EE;&#x6807;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x5148;&#x5C06;&#x9009;&#x9879;&#x4FDD;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x4F46;&#x662F;&#x7A0D;&#x540E;&#x4F1A;&#x5C06;&#x9009;&#x9879;&#x79FB;&#x5230;&#x79BB;&#x76EE;&#x6807;&#x66F4;&#x8FD1;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x901A;&#x8FC7;&#x672C;&#x5730;&#x5316;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x5F97;&#x5230;&#x53EF;&#x91CD;&#x7528;&#x7684;CMake&#x6784;&#x5EFA;&#x5757;&#x3002;</p>
<h2 id="&#x4ECE;&#x53EF;&#x6267;&#x884C;&#x7684;&#x76EE;&#x6807;&#x5F00;&#x59CB;&#xFF0C;&#x8FDB;&#x884C;&#x672C;&#x5730;&#x5316;">&#x4ECE;&#x53EF;&#x6267;&#x884C;&#x7684;&#x76EE;&#x6807;&#x5F00;&#x59CB;&#xFF0C;&#x8FDB;&#x884C;&#x672C;&#x5730;&#x5316;</h2>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x6E90;&#x7801;&#x3002;&#x5728;Vim&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x6E90;&#x6587;&#x4EF6;&#x4F4D;&#x4E8E;<code>src</code>&#x4E0B;&#xFF0C;&#x4E3A;&#x4E86;&#x4FDD;&#x6301;&#x4E3B;<code>CMakeLists.txt</code>&#x7684;&#x53EF;&#x8BFB;&#x6027;&#x548C;&#x53EF;&#x7EF4;&#x6301;&#x6027;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x6587;&#x4EF6;<code>src/CMakeLists.txt</code>&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x6DFB;&#x52A0;&#x5230;&#x4E3B;<code>CMakeLists.txt</code>&#x4E2D;&#xFF0C;&#x4ECE;&#x800C;&#x53EF;&#x4EE5;&#x5728;&#x81EA;&#x5DF1;&#x7684;&#x76EE;&#x5F55;&#x8303;&#x56F4;&#x5185;&#x5904;&#x7406;&#x8BE5;&#x6587;&#x4EF6;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_subdirectory</span>(src)
</code></pre>
<p>&#x5728;<code>src/CMakeLists.txt</code>&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x53EF;&#x6267;&#x884C;&#x76EE;&#x6807;&#xFF0C;&#x5E76;&#x5217;&#x51FA;&#x4ECE;<code>build.log</code>&#x4E2D;&#x83B7;&#x53D6;&#x6240;&#x6709;&#x6E90;&#x7801;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_executable</span>(vim
  arabic.c beval.c buffer.c blowfish.c crypt.c crypt_zip.c dict.c diff.c digraph.c edit.c eval.c evalfunc.c ex_cmds.c ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c farsi.c fileio.c fold.c getchar.c hardcopy.c hashtab.c if_cscope.c if_xcmdsrv.c list.c mark.c memline.c menu.c misc1.c misc2.c move.c mbyte.c normal.c ops.c <span class="hljs-keyword">option</span>.c os_unix.c auto/pathdef.c popupmnu.c pty.c quickfix.c regexp.c screen.c search.c sha256.c spell.c spellfile.c syntax.c tag.c term.c terminal.c ui.c undo.c userfunc.c window.c libvterm/src/encoding.c libvterm/src/keyboard.c libvterm/src/mouse.c libvterm/src/parser.c libvterm/src/pen.c libvterm/src/screen.c libvterm/src/state.c libvterm/src/unicode.c libvterm/src/vterm.c netbeans.c channel.c charset.c json.c main.c memfile.c <span class="hljs-keyword">message</span>.c version.c
  )
</code></pre>
<p>&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x5F00;&#x59CB;&#x3002;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4EE3;&#x7801;&#x751A;&#x81F3;&#x4E0D;&#x4F1A;&#x914D;&#x7F6E;&#xFF0C;&#x56E0;&#x4E3A;&#x6E90;&#x5217;&#x8868;&#x5305;&#x542B;&#x751F;&#x6210;&#x7684;&#x6587;&#x4EF6;&#x3002;&#x8BA8;&#x8BBA;&#x751F;&#x6210;&#x6587;&#x4EF6;&#x548C;&#x94FE;&#x63A5;&#x4F9D;&#x8D56;&#x9879;&#x4E4B;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x628A;&#x8FD9;&#x4E00;&#x957F;&#x5217;&#x8868;&#x62C6;&#x5206;&#x4E00;&#x4E0B;&#xFF0C;&#x4EE5;&#x9650;&#x5236;&#x76EE;&#x6807;&#x4F9D;&#x8D56;&#x9879;&#x7684;&#x8303;&#x56F4;&#xFF0C;&#x5E76;&#x4F7F;&#x9879;&#x76EE;&#x66F4;&#x6613;&#x4E8E;&#x7BA1;&#x7406;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5C06;&#x5B83;&#x4EEC;&#x5206;&#x7EC4;&#x5230;&#x76EE;&#x6807;&#xFF0C;&#x8FD9;&#x5C06;&#x4F7F;CMake&#x66F4;&#x5BB9;&#x6613;&#x5730;&#x627E;&#x5230;&#x6E90;&#x6587;&#x4EF6;&#x4F9D;&#x8D56;&#x9879;&#xFF0C;&#x5E76;&#x907F;&#x514D;&#x5F88;&#x957F;&#x7684;&#x94FE;&#x63A5;&#x884C;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;Vim&#x793A;&#x4F8B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x8FDB;&#x4E00;&#x6B65;&#x4E86;&#x89E3;&#x6765;&#x81EA;<code>src/Makefile</code>&#x548C;<code>src/configure.ac</code>&#x7684;&#x6E90;&#x7801;&#x6587;&#x4EF6;&#x8FDB;&#x884C;&#x5206;&#x7EC4;&#x3002;&#x8FD9;&#x4E9B;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x5927;&#x591A;&#x6570;&#x6E90;&#x6587;&#x4EF6;&#x90FD;&#x662F;&#x5FC5;&#x9700;&#x7684;&#x3002;&#x6709;&#x4E9B;&#x6E90;&#x6587;&#x4EF6;&#x662F;&#x53EF;&#x9009;&#x7684;(<code>netbeans.c</code>&#x5E94;&#x8BE5;&#x53EA;&#x5728;<code>ENABLE_NETBEANS</code>&#x6253;&#x5F00;&#x65F6;&#x6784;&#x5EFA;&#xFF0C;&#x800C;<code>channel.c</code>&#x5E94;&#x8BE5;&#x53EA;&#x5728;<code>ENABLE_CHANNEL</code>&#x6253;&#x5F00;&#x65F6;&#x6784;&#x5EFA;)&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x6240;&#x6709;&#x6E90;&#x4EE3;&#x7801;&#x5206;&#x7EC4;&#x5230;<code>src/libvterm/</code>&#x4E0B;&#xFF0C;&#x5E76;&#x4F7F;&#x7528;<code>ENABLE_TERMINAL</code>&#x53EF;&#x9009;&#x5730;&#x7F16;&#x8BD1;&#x5B83;&#x4EEC;&#x3002;</p>
<p>&#x8FD9;&#x6837;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;CMake&#x7ED3;&#x6784;&#x91CD;&#x7EC4;&#xFF0C;&#x6784;&#x6210;&#x5982;&#x4E0B;&#x7684;&#x6811;&#x7ED3;&#x6784;&#xFF1A;</p>
<pre><code class="lang-shell">.
&#x251C;&#x2500;&#x2500; CMakeLists.txt
&#x2514;&#x2500;&#x2500; src
    &#x251C;&#x2500;&#x2500; CMakeLists.txt
    &#x2514;&#x2500;&#x2500; libvterm
        &#x2514;&#x2500;&#x2500; CMakeLists.txt
</code></pre>
<p>&#x9876;&#x5C42;&#x6587;&#x4EF6;&#x4F7F;&#x7528;<code>add_subdirectory(src)</code>&#x6DFB;&#x52A0;<code>src/CMakeLists.txt</code>&#x3002;<code>src/CMakeLists.txt</code>&#x6587;&#x4EF6;&#x5305;&#x542B;&#x4E09;&#x4E2A;&#x76EE;&#x6807;(&#x4E00;&#x4E2A;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#x548C;&#x4E24;&#x4E2A;&#x5E93;)&#xFF0C;&#x6BCF;&#x4E2A;&#x76EE;&#x6807;&#x90FD;&#x5E26;&#x6709;&#x7F16;&#x8BD1;&#x5B9A;&#x4E49;&#x548C;&#x5305;&#x542B;&#x76EE;&#x5F55;&#x3002;&#x9996;&#x5148;&#x5B9A;&#x4E49;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_executable</span>(vim
  main.c
  )

target_compile_definitions(vim
  PRIVATE
      <span class="hljs-string">&quot;HAVE_CONFIG_H&quot;</span>
  )
</code></pre>
<p>&#x7136;&#x540E;&#xFF0C;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x9700;&#x8981;&#x6E90;&#x7801;&#x6587;&#x4EF6;&#x7684;&#x76EE;&#x6807;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(basic_sources <span class="hljs-string">&quot;&quot;</span>)

target_sources(basic_sources
  PRIVATE
    arabic.c beval.c blowfish.c buffer.c charset.c
    crypt.c crypt_zip.c dict.c diff.c digraph.c
    edit.c eval.c evalfunc.c ex_cmds.c ex_cmds2.c
    ex_docmd.c ex_eval.c ex_getln.c farsi.c fileio.c
    fold.c getchar.c hardcopy.c hashtab.c if_cscope.c
    if_xcmdsrv.c json.c list.c main.c mark.c
    memfile.c memline.c menu.c <span class="hljs-keyword">message</span>.c misc1.c
    misc2.c move.c mbyte.c normal.c ops.c
    <span class="hljs-keyword">option</span>.c os_unix.c auto/pathdef.c popupmnu.c pty.c
    quickfix.c regexp.c screen.c search.c sha256.c
    spell.c spellfile.c syntax.c tag.c term.c
    terminal.c ui.c undo.c userfunc.c version.c
    window.c
  )

target_include_directories(basic_sources
  PRIVATE
    <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/proto
    <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>
    <span class="hljs-variable">${CMAKE_CURRENT_BINARY_DIR}</span>
  )

target_compile_definitions(basic_sources
  PRIVATE
      <span class="hljs-string">&quot;HAVE_CONFIG_H&quot;</span>
  )

<span class="hljs-keyword">target_link_libraries</span>(vim
  PUBLIC
      basic_sources
  )
</code></pre>
<p>&#x7136;&#x540E;&#xFF0C;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x53EF;&#x9009;&#x6E90;&#x7801;&#x6587;&#x4EF6;&#x7684;&#x76EE;&#x6807;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(extra_sources <span class="hljs-string">&quot;&quot;</span>)

<span class="hljs-keyword">if</span>(ENABLE_NETBEANS)
  target_sources(extra_sources
    PRIVATE
        netbeans.c
    )
<span class="hljs-keyword">endif</span>()

<span class="hljs-keyword">if</span>(ENABLE_CHANNEL)
  target_sources(extra_sources
    PRIVATE
        channel.c
    )
<span class="hljs-keyword">endif</span>()

target_include_directories(extra_sources
  PUBLIC
    <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/proto
    <span class="hljs-variable">${CMAKE_CURRENT_BINARY_DIR}</span>
  )

target_compile_definitions(extra_sources
  PRIVATE
      <span class="hljs-string">&quot;HAVE_CONFIG_H&quot;</span>
  )

<span class="hljs-keyword">target_link_libraries</span>(vim
  PUBLIC
      extra_sources
  )
</code></pre>
<p>&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x4EE3;&#x7801;&#xFF0C;&#x5BF9;&#x8FDE;&#x63A5;<code>src/libvterm/</code>&#x5B50;&#x76EE;&#x5F55;&#x8FDB;&#x884C;&#x9009;&#x62E9;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">if</span>(ENABLE_TERMINAL)
  <span class="hljs-keyword">add_subdirectory</span>(libvterm)

  <span class="hljs-keyword">target_link_libraries</span>(vim
    PUBLIC
        libvterm
    )
<span class="hljs-keyword">endif</span>()
</code></pre>
<p>&#x5BF9;&#x5E94;&#x7684;<code>src/libvterm/CMakeLists.txt</code>&#x5305;&#x542B;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;:</p>
<pre><code class="lang-cmake"><span class="hljs-keyword">add_library</span>(libvterm <span class="hljs-string">&quot;&quot;</span>)

target_sources(libvterm
  PRIVATE
    src/encoding.c
    src/keyboard.c
    src/mouse.c
    src/parser.c
    src/pen.c
    src/screen.c
    src/state.c
    src/unicode.c
    src/vterm.c
  )

target_include_directories(libvterm
  PUBLIC
      <span class="hljs-variable">${CMAKE_CURRENT_LIST_DIR}</span>/<span class="hljs-keyword">include</span>
  )

target_compile_definitions(libvterm
  PRIVATE
    <span class="hljs-string">&quot;HAVE_CONFIG_H&quot;</span>
    <span class="hljs-string">&quot;INLINE=&quot;</span>
    <span class="hljs-string">&quot;VSNPRINTF=vim_vsnprintf&quot;</span>
    <span class="hljs-string">&quot;IS_COMBINING_FUNCTION=utf_iscomposing_uint&quot;</span>
    <span class="hljs-string">&quot;WCWIDTH_FUNCTION=utf_uint2cells&quot;</span>
  )
</code></pre>
<p>&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x4ECE;<code>build.log</code>&#x4E2D;&#x83B7;&#x53D6;&#x4E86;&#x7F16;&#x8BD1;&#x4FE1;&#x606F;&#x3002;&#x6811;&#x7ED3;&#x6784;&#x7684;&#x4F18;&#x70B9;&#x662F;&#xFF0C;&#x76EE;&#x6807;&#x7684;&#x5B9A;&#x4E49;&#x9760;&#x8FD1;&#x6E90;&#x7684;&#x4F4D;&#x7F6E;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x51B3;&#x5B9A;&#x91CD;&#x6784;&#x4EE3;&#x7801;&#x5E76;&#x91CD;&#x547D;&#x540D;&#x6216;&#x79FB;&#x52A8;&#x76EE;&#x5F55;&#xFF0C;&#x63CF;&#x8FF0;&#x76EE;&#x6807;&#x7684;CMake&#x6587;&#x4EF6;&#x5C31;&#x4F1A;&#x968F;&#x7740;&#x6E90;&#x6587;&#x4EF6;&#x4E00;&#x8D77;&#x79FB;&#x52A8;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x7684;&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#x8FD8;&#x6CA1;&#x6709;&#x914D;&#x7F6E;(&#x9664;&#x975E;&#x5728;&#x6210;&#x529F;&#x7684;Autotools&#x6784;&#x5EFA;&#x4E4B;&#x540E;&#x5C1D;&#x8BD5;&#x914D;&#x7F6E;)&#xFF0C;&#x73B0;&#x5728;&#x6765;&#x8BD5;&#x8BD5;:</p>
<pre><code class="lang-shell">$ mkdir -p build
$ cd build
$ cmake ..

-- The C compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
CMake Error at src/CMakeLists.txt:12 (add_library):
Cannot find source file:
auto/pathdef.c
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
</code></pre>
<p>&#x8FD9;&#x91CC;&#x9700;&#x8981;&#x751F;&#x6210;<code>auto/pathdef.c</code>(&#x548C;&#x5176;&#x4ED6;&#x6587;&#x4EF6;)&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5728;&#x4E0B;&#x4E00;&#x8282;&#x4E2D;&#x8003;&#x8651;&#x8FD9;&#x4E9B;&#x6587;&#x4EF6;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="15.0-chinese.html" class="navigation navigation-prev " aria-label="Previous page: 第15章 使用CMake构建已有项目">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="15.2-chinese.html" class="navigation navigation-next " aria-label="Next page: 15.2 生成文件并编写平台检查">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"15.1 如何开始迁移项目","level":"1.18.1","depth":2,"next":{"title":"15.2 生成文件并编写平台检查","level":"1.18.2","depth":2,"path":"content/chapter15/15.2-chinese.md","ref":"content/chapter15/15.2-chinese.md","articles":[]},"previous":{"title":"第15章 使用CMake构建已有项目","level":"1.18","depth":1,"path":"content/chapter15/15.0-chinese.md","ref":"content/chapter15/15.0-chinese.md","articles":[{"title":"15.1 如何开始迁移项目","level":"1.18.1","depth":2,"path":"content/chapter15/15.1-chinese.md","ref":"content/chapter15/15.1-chinese.md","articles":[]},{"title":"15.2 生成文件并编写平台检查","level":"1.18.2","depth":2,"path":"content/chapter15/15.2-chinese.md","ref":"content/chapter15/15.2-chinese.md","articles":[]},{"title":"15.3 检测所需的链接和依赖关系","level":"1.18.3","depth":2,"path":"content/chapter15/15.3-chinese.md","ref":"content/chapter15/15.3-chinese.md","articles":[]},{"title":"15.4 复制编译标志","level":"1.18.4","depth":2,"path":"content/chapter15/15.4-chinese.md","ref":"content/chapter15/15.4-chinese.md","articles":[]},{"title":"15.5 移植测试","level":"1.18.5","depth":2,"path":"content/chapter15/15.5-chinese.md","ref":"content/chapter15/15.5-chinese.md","articles":[]},{"title":"15.6 移植安装目标","level":"1.18.6","depth":2,"path":"content/chapter15/15.6-chinese.md","ref":"content/chapter15/15.6-chinese.md","articles":[]},{"title":"15.7 进一步迁移的措施","level":"1.18.7","depth":2,"path":"content/chapter15/15.7-chinese.md","ref":"content/chapter15/15.7-chinese.md","articles":[]},{"title":"15.8 项目转换为CMake的常见问题","level":"1.18.8","depth":2,"path":"content/chapter15/15.8-chinese.md","ref":"content/chapter15/15.8-chinese.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro","-sharing","github","pageview-count"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/arcticfox1919"},"search-pro":{},"pageview-count":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"陈晓伟 chenxiaowei","pdf":{"pageNumbers":false,"fontSize":30,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":30,"left":30,"top":30,"bottom":50}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《CMake Cookbook》中文版","language":"zh-hans","gitbook":"*","description":"作为对《CMake Cookbook》英文版的中文翻译。","direction":"ltr"},"file":{"path":"content/chapter15/15.1-chinese.md","mtime":"2020-09-22T10:39:01.916Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-22T11:21:21.825Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

